/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package za.co.pass.jtorrenteditor.list.cellrenderer;

import java.awt.Component;
import java.awt.Font;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

/**
 *
 * @author alabuschagne
 */
public class FixedTextWidthListCellRenderer implements ListCellRenderer
{
    private boolean monospaced = false;
    private Font monoFont = null;
    private String abc;

    public FixedTextWidthListCellRenderer()
    {
    }

    public FixedTextWidthListCellRenderer(boolean monospaced)
    {
        this.monospaced = monospaced;
    }

    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
    {
        JLabel label = new JLabel();
        Font font = label.getFont();
        if(monospaced && (monoFont == null))
        {
            monoFont = new Font("Monospaced", Font.PLAIN, font.getSize());
        }

        if(monoFont != null)
        {
            label.setFont(monoFont);
        }
        else
        {
            label.setFont(font.deriveFont(Font.PLAIN));
        }
        if(isSelected)
        {
            label.setFont(font.deriveFont(Font.BOLD));
        }
        label.setText((String) value);
        return label;
    }
}
